<?php
// 用户模型
class MemberModel extends CommonModel {
	public $_validate	=	array(
		array('account','/^[a-z]\w{3,}$/i','帐号格式错误'),
		array('trueName','require','真实姓名必须'),
		array('telephone','/^[0-9]\d{10}/','手机号码是11位数字'),
		array('password','require','密码必须'),
		array('cardNumber','require','卡号必须'),
		array('salerId','checkSalerId','请选择销售顾问',1,'callback'),
		array('cardTypeId','checkCardTypeId','会员卡必须',1,'callback'),
		array('account','','帐号已经存在',self::EXISTS_VAILIDATE,'unique',self::MODEL_INSERT),
		array('telephone','','手机号码已经存在',self::EXISTS_VAILIDATE,'unique',self::MODEL_BOTH),
		);

	//检测销售顾问
	protected function checkSalerId(){
		if(isset($_REQUEST['salerId'])){
			$salerId = $_REQUEST['salerId'];
			if($salerId==0){
				return false;
			}else{
				return true;
			}
		}
		return true;
	}
	//检测是否已选会员卡类型
	protected function checkCardTypeId(){
		if(isset($_REQUEST['cardTypeId'])){
			$salerId = $_REQUEST['cardTypeId'];
			if($salerId==0){
				return false;
			}else{
				return true;
			}
		}
		return true;
	}



	protected function pwdHash() {
		if(isset($_POST['password'])) {
			return pwdHash($_POST['password']);
		}else{
			return false;
		}
	}
		// 自动填充设置
	protected $_auto	 =	 array(
		array('password','pwdHash',self::MODEL_BOTH,'callback'),
		array('createTime','time',self::MODEL_INSERT,'function'),
	);

	public function findById($id){
		$member = $this->getById($id);
		if($member){
			return $member['trueName'];
		}
	}
}
?>